HeroS _initf(int posx,int posy,int dir,int type,char name[20]){
	int lifeType;
	int defenseType;
	int attackType;
	int attackRangeType;
	char infoType[30];
	char drawType[10];
		switch(type){
		case herot1:
		
		lifeType = 200;
		defenseType = 3;
		attackType = 1;
		attackRangeType = 4;
		strcpy(infoType,"c90,maxLife is big");
		strcpy(drawType,P1);
		
		break;
		case herot2:
		lifeType = 100;
		defenseType = 1;
		attackType = 2;
		attackRangeType = 1;
		strcpy(infoType,"c99,attack higher");
		strcpy(drawType,P2);
		break;
		case herot3:
		lifeType = 150;	
		defenseType = 10;
		attackType = 1;
		attackRangeType = 1;
		strcpy(infoType,"c11,defense higher");
		strcpy(drawType,P3);
		break;
		}
		
	HeroS hero={
		.pos = {.x=posx,.y=posy},
		.maxlife=lifeType,
		.attack=attackType,
		.attackSpeed=1,
		.coldtime=30,
		.type=type,
		.moveSpeed=1,
		.curlife=lifeType,
		.level=1,
		.exp = 1,
		.dir = dir,
		.coin=300,
		.defense=defenseType,
		.boomAttack=0.1,
		.attackRange=attackRangeType,
		strcpy(hero.info,infoType),
		strcpy(hero.draw,drawType),
		strcpy(hero.name,name)
		};
	return hero;
}
void _showf(HeroS *player,HeroS *enemy){

	// showHero(hero.pos,hero.draw);
	showHerosWithConsole(player,enemy);
}
Hero _hero={._init=_initf,
	._show=_showf
};

void showHero(Vector2S v2s,const char *str){
	gotoxy(v2s.x,v2s.y);
	puts(str);
}
void showHeros(HeroS *player,HeroS *enemy){
	showHero(player->pos,player->draw);	
	showHero(enemy->pos,enemy->draw);
	}
void showHerosWithConsole(HeroS *player,HeroS *enemy){
		showHero(player->pos,player->draw);	
		showHero(enemy->pos,enemy->draw);
		
		gotoxy(0,H+2+player->type);
		if(_config.isOpenInfo){
		printf("%s:%s,hp:%d,物攻:%d,物防:%d,攻击范围:%d\n","鲁班七号",player->draw,player->curlife,player->attack,player->defense,player->attackRange);
	
		printf("skill CD u:%d c:%d e:%d\n",skilltimer*60,curetimer*60, estimer*60);
		
		printf("%9s:%s,hp:%d,物攻:%d,物防:%d,攻击范围:%d","凯",enemy->draw,enemy->curlife,enemy->attack,enemy->defense,enemy->attackRange);
		}
		
		if(_config.isOpenHelp){
		printf(HELP_TXT1);
		printf(HELP_TXT2);
		}
		fflush(stdout);
}	
int isInAtRange(HeroS orgHero,Vector2S otherV2s){
	int isInAtRange = 0;
	int atRange = orgHero.attackRange;
	double dis = (_vector2._getDis(orgHero.pos,otherV2s));
	if(dis <= atRange) isInAtRange = 1;
	else isInAtRange = 0;
	
	return isInAtRange;	
}
void getPosByDir(Vector2S *v2s,int dir,int range){
	
	switch(dir){
		case eUp:
		v2s->y =v2s->y - range;
		break;
		case eDown:
		v2s->y=v2s->y + range;
		
		break;
		case eLeft:
		v2s->x=v2s->x -range;
		break;
		case eRight:
		v2s->x=v2s->x +range;
		break;
		}
}
void showHeroAttackRange(HeroS heroS,char rangeStr[4]){
	
		for(int i=0;i<4;i++){
			for(int j=0;j<=heroS.attackRange;j++){
			Vector2S v2sRange = heroS.pos;
			getPosByDir(&v2sRange,i,j);
			gotoxy(v2sRange.x,v2sRange.y);
			puts(rangeStr);			
			}
		}		
}
void* showRtHome(void * rtArgs){

	    int timer=6000;
	    Vector2S v2s = {.x=0,.y=H+10};
		while(timer>0){
			gotoxy(v2s.x,v2s.y);
			int pro = ((6000-timer)/6000.0)*100;
			printf("RtHome:%d%%",pro);			
			fflush(stdout);
			sleep_ms(10);
			timer-=60;			
	}	
	player.heros.pos.x = 2;
	player.heros.pos.y = (H + 1) / 2+1;
}
void attack(HeroS player,HeroS other){
	if(isInAtRange(player,other.pos)){
		int realAttack = player.attack - enemy.heros.defense;
		realAttack = realAttack>0?realAttack:1;
		if(enemy.heros.curlife >= realAttack)
		enemy.heros.curlife = enemy.heros.curlife - realAttack;
	}

}
void extraSkill(Hero *hero){
	int esdis = 2;
	switch(hero->heros.dir){
		case eUp:
			if(hero->heros.pos.y - esdis>2)
				hero->heros.pos.y = hero->heros.pos.y - esdis;
			else
				hero->heros.pos.y = 2;
		break;	
		case eRight:
			if(hero->heros.pos.x + esdis<W)
				hero->heros.pos.x = hero->heros.pos.x + esdis;
			else
				hero->heros.pos.x = W-1;
		break;	
		case eDown:
			if(hero->heros.pos.y + esdis<H)
				hero->heros.pos.y = hero->heros.pos.y + esdis;
			else
				hero->heros.pos.y = H;
		break;	
		case eLeft:
			if(hero->heros.pos.x - esdis>2)
				hero->heros.pos.x= hero->heros.pos.x - esdis;
			else
				hero->heros.pos.x = 2;			
		break;	
		
	}
}
char heroCtrl(Hero * hero, int input)
{
	
	switch (input)
	{
	case Up:
			hero->heros.dir = eUp;
		if (hero->heros.pos.y - 1 > 1)
			hero->heros.pos.y = hero->heros.pos.y - 1;
		break;
	case Down:
				hero->heros.dir = eDown;
		if (hero->heros.pos.y + 1 < H + 1)
			hero->heros.pos.y = hero->heros.pos.y + 1;
		break;
	case Left:
				hero->heros.dir = eLeft;
		if (hero->heros.pos.x - 1 > 1)
			hero->heros.pos.x = hero->heros.pos.x - 1;
		break;
	case Right:
				hero->heros.dir = eRight;
		if (hero->heros.pos.x + 1 < W)
			hero->heros.pos.x = hero->heros.pos.x + 1;
		break;
	case RtHome:{
		pthread_t ntid;
		pthread_create(&ntid,NULL,showRtHome,NULL);
		pthread_detach(ntid);
	//pthread_join(ntid,NULL);
		
	}
		break;
	case Attack:
	
		showHeroAttackRange(hero->heros,"+");
		attack(player.heros,enemy.heros);
		
		
		break;
	case OpenInfo:
		_config.isOpenInfo=_config.isOpenInfo?0:1;
	break;
	case OpenMap:
		_config.isOpenMap=_config.isOpenMap?0:1;	
	break;
	case OpenHelp:
		_config.isOpenHelp=_config.isOpenHelp?0:1;
	break;
	case Skill0:
		
		if(skilltimer==0){
		
		initBombs(hero->heros.pos);
		_bomb._show(directB1.bombS);
		skilltimer=hero->heros.coldtime;			
	
		}	
	break;
	case Cure:
	
	if(curetimer==0 && player.heros.curlife < player.heros.maxlife){
		
		player.heros.curlife = (player.heros.curlife+20)<=player.heros.maxlife?(player.heros.curlife+20):player.heros.maxlife;
		curetimer=player.heros.coldtime;	
	}
		
	break;
	
	case ExtraSkill:
	if(estimer==0){
		extraSkill(hero);
		estimer = player.heros.coldtime;
		}
		
	break;
	case Shop:
		_config.isOpenShop=_config.isOpenShop?0:1;	
	break;
	case Equipment1:
		if(player.heros.coin<500){
			_config.isOpenTipCoin = 1;	
		}else
		player.heros.attack = player.heros.attack + 5; 
	break;
	
	case Equipment2:
		if(player.heros.coin<1000){
			_config.isOpenTipCoin = 1;	
		}else{
	
		player.heros.defense = player.heros.defense + 5; 
		player.heros.maxlife = player.heros.maxlife + 50;
		}
	break;
	}
	if(curetimer!=0)
	curetimer--;
	if(skilltimer!=0)
	skilltimer--;
	if(estimer!=0)
	estimer--;
	
	
	if (hero->heros.pos.x <= 0 || hero->heros.pos.x > W || hero->heros.pos.y <= 0
		|| hero->heros.pos.y > H)
		return Quit;
}
void update(){
	
}
void initPlayer(int type){
	char buf[20];
	VAR_NAME(buf,player);
	HeroS playerS = _hero._init(2, (H + 1) / 2 + 1, eRight, type,buf);
	_hero.heros = playerS;
	player = _hero;	
}
void initEnemy(int type){
	char buf[20];
	VAR_NAME(buf,enemy);
	HeroS enemyS = _hero._init(W - 1, (H + 1) / 2 + 1,eLeft, type,buf);
	_hero.heros = enemyS;
	_hero.heros.dir = eLeft;
	enemy = _hero;
}
void initHeros(int ptype)
{
	initPlayer(ptype);
	initEnemy(herot2);		
}
